#ifndef _OM_LOG_H_
#define _OM_LOG_H_

#include "OmPrerequisite.h"

#include "OmSingleton.h"
#include "OmPrerequisite.h"
#include "OmString.h"
#include "OmMutex.h"

namespace OmPublic
{
	class OmExport Log
	{
		public:
			enum LogLevel{LL_NORMAL=0, LL_LOW, LL_HIGH, LL_CRITICAL};
		
		public:
			Log(const String & name, bool debug);
			~Log();

			void logMessage(const String & message,LogLevel ll, bool maskDebug)	;
			const String & getName() const {return mName;}

		protected:
			OM_AUTO_MUTEX
			std::wofstream mfpLog; 
			bool mOnlyDebug; 
			String mName;
			typedef std::vector<LogListener*> LogListeners;
			LogListeners mLogListeners;

					
	};
	
	class OmExport LogListener
	{
	public:
		virtual ~LogListener(){}

		virtual void messageLogged(const String & message, Log::LogLevel, bool maskDebug, const String & logName) = 0;

	};

	class OmExport LogManager : public Singleton<LogManager>
	{
	public:
		LogManager();
		~LogManager();

		Log* createLog(const String & name, bool defaultLog = false, bool debug = true);
		Log* getLog(const String & name);
		Log* getDefaultLog();
		Log* setDefaultLog(Log* log);
		void destroyLog(const String & name);
		void destroyLog(Log* log);
		void logMessage(const String & message, Log::LogLevel ll = Log::LL_NORMAL, bool debug = true);

		private:
			OM_AUTO_MUTEX
			typedef std::map<wstring, Log*, std::less<wstring> >	LogList;
			LogList mLogs;
			Log* mDefaultLog; // default output log, if donot indicate log, use default log 
		
	};
}

#endif